package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/12.
 */

public class triangleView extends BaseView {
    public triangleView(Context context) {
        super(context);
        init();
    }

    public triangleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(ProportionUtils.getInstance().adapterInt(80), ProportionUtils.getInstance().adapterInt(77));
    }

    String info;

    public void setInfo(String info) {
        this.info = info;
        invalidate();
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        if (info == null) {
            return;
        }
        paint.setStyle(Paint.Style.FILL_AND_STROKE);//可以画实心三角形
        paint.setStrokeWidth(0);
        paint.setColor(Color.parseColor("#4B97F0"));
        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(getWidth(), 0);
        path.lineTo(0, getHeight());
        path.close();
        canvas.drawPath(path, paint);
        paint.setColor(Color.parseColor("#ffffff"));
        int textSize = ProportionUtils.getInstance().adapterInt(32);
        paint.setStrokeWidth(0);
        paint.setTextSize(textSize);
        int x=ProportionUtils.getInstance().adapterInt(getWidth()/5);
        int y=ProportionUtils.getInstance().adapterInt(getHeight()/3);
        canvas.drawText(info, x, y, paint);
    }
}
